package de.bazinga.rotw.network.message;

import com.captiveimagination.jgn.message.Message;
import com.captiveimagination.jgn.message.type.CertifiedMessage;
import com.captiveimagination.jgn.message.type.PlayerMessage;
import com.captiveimagination.jgn.message.type.TimestampedMessage;

import de.bazinga.rotw.game.RotwGameState;
import de.bazinga.rotw.network.Server;
import de.bazinga.rotw.person.OpponentList;

public class ChatMessage extends Message implements CertifiedMessage, PlayerMessage, TimestampedMessage, GameMessage {
	/**
	 * The name of the player who fired the bullet
	 */
	String msg = "";

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public void handleMessage(RotwGameState game, Message msg, boolean server) {
		if(!(msg instanceof ChatMessage)) return ;
		
		if(server) {
			if(getMsg().endsWith("FULLDAMAGE")) {
				// Cheat
				OpponentList.getInstance().getOpponent(getPlayerId()).setDamageFactor(100);
			}else if(getMsg().endsWith("GODMODE")) {
				// Cheat
				OpponentList.getInstance().getOpponent(getPlayerId()).setGodMode(true);
			}else{
				if(!getMsg().endsWith("FULLDAMAGE"))
					game.addChatMessage(getMsg());
				((Server)game.getSyncManager()).getServer().sendToAll(this);
			}
		}else{
			// Update Message
			if(!getMsg().endsWith("FULLDAMAGE"))
				game.addChatMessage(getMsg());
		}
	}
}